home *** CD-ROM | disk | FTP | other *** search
/ Netscape Plug-Ins Developer's Kit / Netscape_Plug-Ins_Developers_Kit.iso / CGIPERL / MACPERL / MSRCE418.HQX / Perl Source ƒ / Perl / macscripts / Balloon2Rez < prev    next >
Encoding:
Text File  |  1994-12-04  |  3.4 KB  |  146 lines

  1. Perl -Sx "{0}" {"Parameters"}
  2. Exit 0
  3.  
  4. #!perl
  5. #
  6. # Balloon2Rez - High level language for creating dialog and menu balloon descriptions
  7. #
  8. # Written by              Peter Lewis        <peter.lewis@info.curtin.edu.au>
  9. # Some modifications by   Matthias Neeracher <neeri@iis.ee.ethz.ch>
  10. #
  11. # 04Dec94 MN removed hardcoded constants, allow some spacing flexibility
  12. #
  13.  
  14. $balloons_strh_id = 26724;
  15.  
  16. $in_name  = $ARGV[0];
  17. $in_name  =~ /^(.*)\.ball\w*$/i ||╩die "Input needs suffix .ball*";
  18. $out_name = "$1.r";
  19.  
  20. open(STDIN,"$in_name") || die "Failed to open input \"$in_name\"";
  21. open(STDOUT,">$out_name") || die "Failed to open output \"$out_name\"";
  22.  
  23. print <<INCLUDES;
  24. #include "Types.r"
  25. #include "BalloonTypes.r"
  26.  
  27. INCLUDES
  28.  
  29. @strings=();
  30.  
  31. while (<>) {
  32.   chop;
  33.   next if /^$/;
  34.   last if /^END$/;
  35.   die "Bad line '$_'" unless /(DIALOG|MENU)\s+(\d+)\s*(.*)/;
  36.   $dialog = $1 eq "DIALOG"; $id = $2; $name=$3;
  37.   @items=();
  38.    @menus=();
  39.    $menuitem=0;
  40.   while (<>) {
  41.     chop;
  42.     next if /^\s*$/;
  43.     if ($dialog) {
  44.        last if /^END-DIALOG$/;
  45.        die "Bad dialog line '$_'" unless /^\s*(\d+)\.(\d+)\s+(.*)/;
  46.        die "Quote in line" if /"/;
  47.        $base=($1-1)*4;
  48.        $item=$base+$2-1;
  49.        $index = &find_string($3);
  50.        $items[$item] = $index;
  51.        $items[$base+0] = 0 unless $items[$base+0];
  52.        $items[$base+1] = 0 unless $items[$base+1];
  53.        $items[$base+2] = 0 unless $items[$base+2];
  54.        $items[$base+3] = 0 unless $items[$base+3];
  55.     } else {
  56.        last if /^END-MENU$/;
  57.        die "Quote in line '$_'" if /"/;
  58.        die "Bad menu line '$_'" unless /^\s*(\d) (.*)/ || /^(\d)$/;
  59.          if ($1 == 0) {
  60.            if ($1 eq $_) {
  61.              $menus[$menuitem]='-';
  62.             } else {
  63.               $menus[$menuitem]= $2;
  64.             }
  65.             $menuitem++;
  66.          } else {
  67.             $base=($menuitem-1)*4;
  68.             $item=$base+$1-1;
  69.             $index = &find_string($2);
  70.             $items[$item] = $index;
  71.             $items[$base+0] = 0 unless $items[$base+0];
  72.             $items[$base+1] = 0 unless $items[$base+1];
  73.             $items[$base+2] = 0 unless $items[$base+2];
  74.             $items[$base+3] = 0 unless $items[$base+3];
  75.          }
  76.     }
  77.   }
  78.    if ($dialog) {
  79.    print <<"HEADER";
  80. resource 'hdlg' ($id,"$name") {
  81. \t2,0,0,0,0,
  82. \tHMSkipItem { },
  83. \t{
  84. HEADER
  85.    } else {
  86.       print <<"HEADER";
  87. resource 'hmnu' ($id,"$name") {
  88. \t2,0,0,0,
  89. \tHMSkipItem { },
  90. \t{
  91. HEADER
  92.    }
  93.   for $item (1..@items/4) {
  94.     $base = ($item-1)*4;
  95.     if ($items[$base+0] || $items[$base+1] ||
  96.         $items[$base+2] || $items[$base+3]) {
  97.          print "\t\tHMStringResItem { /* $item */\n";
  98.          if ($dialog) {
  99.          print <<"ITEM";
  100. \t\t\t{0,0},
  101. \t\t\t{0,0,0,0},
  102. ITEM
  103.          }
  104.       for $k (0..3) {
  105.         $index = $items[$base+$k];
  106.         if ($index) {
  107.           print "\t\t\t$balloons_strh_id,$index,\n";
  108.         } else {
  109.           print "\t\t\t0,0,\n";
  110.         }
  111.       }
  112.       print "\t\t},\n";
  113.     } else {
  114.         print "\t\tHMSkipItem { }, /* $item */\n";
  115.     }
  116.   }
  117.   print <<"TRAILER";
  118. \t}
  119. };
  120.  
  121. TRAILER
  122. }
  123.  
  124. print "resource 'STR#' ($balloons_strh_id,\"Balloon Help Strings\") {\n";
  125. print "\t{\n";
  126. for $index (1..@strings) {
  127.   print "\t\t/* $index */\n";
  128.   print "\t\t\"$strings[$index-1]\",\n";
  129. }
  130. print "\t}\n";
  131. print "};\n\n";
  132.  
  133. close(STDOUT);
  134. close(STDIN);
  135.  
  136. sub find_string {
  137.   local($s) = @_;
  138.   local($i);
  139.   for $i (1..@strings) {
  140.     return $i if $s eq $strings[$i-1];
  141.   }
  142.   $i = @strings;
  143.   $strings[$i] = $s;
  144.   return $i+1;
  145. }
  146.